package me.hunche.app.job;

import java.util.Date;
import java.util.List;

import me.hunche.app.domain.Activity;
import me.hunche.app.service.ActivityService;
import me.hunche.app.service.NotifyService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hp.hpl.helper.misc.DateHelper;

//@Service
public class RemindJob {
	
	private static final Logger logger = Logger.getLogger(RemindJob.class);

	@Autowired private NotifyService ns;
//	@Autowired private ActivityDao ad;
	@Autowired private ActivityService activityService;
	
	private Integer[] triggerDays =  {7,6,5,4,3,2};
	
	public void run(){
		if(logger.isDebugEnabled()){
			logger.debug("Remind1Job start");
		}
		
		for(Integer days:triggerDays){
			Date ds = DateHelper.dayStart(DateHelper.now(), days);
//			Date d = new Date(ds.getTime());
			List<Activity> as = activityService.findByActivityDateAndStatus(ds,Activity.STATUS_PREP);
			if(as!=null && !as.isEmpty()){
				for(Activity a:as){
					ns.remind(a);
				}
			}
		}
		
		if(logger.isDebugEnabled()){
			logger.debug("Remind1Job end");
		}
	}
}
